<!DOCTYPE html>
<html lang="en">

<head>
	<title>用户管理页</title>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<link rel="stylesheet" href="css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-responsive.min.css" />
	<link rel="stylesheet" href="css/uniform.css" />
	<link rel="stylesheet" href="css/select2.css" />
	<link rel="stylesheet" href="css/matrix-style2.css" />
	<link rel="stylesheet" href="css/matrix-media.css" />
	<link href="font-awesome/css/font-awesome.css" rel="stylesheet" />
	<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700,800' rel='stylesheet' type='text/css'>
</head>

<body>

	<div id="content">
		<div id="content-header">
			<h1>用户信息管理</h1>
		</div>
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<div class="widget-box">
						<div class="widget-title"> <span class="icon"> <i class="icon-info-sign"></i> </span>
							<h5>修改密码</h5>
						</div>
						<div class="widget-content nopadding">
							<form class="form-horizontal" method="post" action="#" name="password_validate"
								id="password_validate" novalidate="novalidate">
								<div class="control-group">
									<label class="control-label">密码</label>
									<div class="controls">
										<input type="password" name="pwd" id="pwd">

									</div>
								</div>
								<div class="control-group">
									<label class="control-label">确认密码</label>
									<div class="controls">
										<input type="password" name="pwd2" id="pwd2">

									</div>
								</div>
								<div class="form-actions">
									<input type="button" value="保存" class="btn btn-success" id="btn-success">
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<script src="http://www.jq22.com/jquery/jquery-1.7.1.js"></script>
	<script src="js/jquery.ui.custom.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/jquery.uniform.js"></script>
	<script src="js/select2.min.js"></script>
	<script src="js/jquery.dataTables.min.js"></script>
	<script src="js/matrix.js"></script>
	<script src="js/matrix.tables.js"></script>

</body>
<script src="js/myquery.js"></script>
<script>
	(function () {
		let password = document.querySelector('#pwd');
		let newPsw = document.querySelector('#pwd2');
		let btnsuccess = document.querySelector('#btn-success');

		newPsw.onblur = () => {
			let psw = password.value.trim();
			let psw2 = newPsw.value.trim();
			if (psw2 != psw) {
				alert('输入的密码不一致，请重新输入')
				psw.value = psw2.value = '';
				psw.focus();
			}
		}

		let name = getCookie('username');
		// console.log(name);
		btnsuccess.onclick = () => {
			let psw = password.value.trim();
			let psw2 = newPsw.value.trim();
			console.log(psw);
			console.log(psw2);
			if (psw && psw2) {
				ajax({
					type: 'post',
					url: 'api/editpsw.php',
					data: {
						psw: psw,
						name: name
					},
					success: str => {
						console.log(str);
						if (str == 'flase') {
							alert('密码修改不成功');
						} else {
							alert('密码修改成功');
						}
					}
				})
			} else {
				alert('请输入密码')
			}
		}
	})();
</script>

</html>